// 获取应用实例
const app = getApp()

Page({
	data: {
		img_src:app.globalData.img_src,
		counter:"请选择专柜",
		array:[
      [ "北京","上海","云南","内蒙古","吉林","四川","天津","宁夏","安徽","山东","山西","广东","广西","新疆","江苏","江西","河北","河南","浙江","湖北","湖南","甘肃","福建","贵州","辽宁","重庆","陕西","青海","黑龙江"],
		["上海"],["上海港汇","上海兴业太古汇","上海百盛淮海","上海大丸百货","上海梅龙镇伊势丹","上海国金","上海东方商厦徐汇","上海第一八佰伴","上海久光","上海东方商厦南东","上海新世界","上海前滩太古汇","上海万象城"]
		],
		indexarr: [1,0,0],
		tmparr:[1,0,0],
		cityarr: {
			"广西": ["南宁"],
			"广东": ["深圳", "广州", "佛山", "东莞"],
			"湖北": ["宜昌", "武汉"],
			"江西": ["南昌"],
			"湖南": ["长沙"],
			"云南": ["昆明"],
			"贵州": ["贵阳"],
			"上海": ["上海"],
			"北京": ["北京"],
			"四川": ["成都"],
			"重庆": ["重庆"],
			"江苏": ["常州", "南京", "徐州", "南通", "淮安", "苏州", "无锡"],
			"福建": ["福州", "厦门"],
			"浙江": ["杭州", "宁波", "温州", "义乌", "金华"],
			"安徽": ["合肥"],
			"河北": ["保定", "石家庄", "唐山"],
			"内蒙古": ["包头", "呼和浩特"],
			"天津": ["天津"],
			"山西": ["太原"],
			"河南": ["郑州", "洛阳"],
			"新疆": ["乌鲁木齐"],
			"甘肃": ["兰州"],
			"山东": ["济南", "淄博", "聊城", "临沂", "东营", "济宁", "烟台", "青岛"],
			"陕西": ["西安"],
			"青海": ["西宁"],
			"宁夏": ["银川"],
			"辽宁": ["鞍山", "沈阳", "大连"],
			"吉林": ["吉林", "长春"],
			"黑龙江": ["哈尔滨"]
	},
		counterarr:{
			"南宁": ["南宁万象城", "南宁梦之岛", "南宁水晶城"],
			"深圳": ["深圳万象天地", "深圳罗湖万象城", "深圳海雅缤纷城", "深圳福田COCOPARK", "深圳茂业华强北", "深圳龙华壹方城", "深圳卓悦汇"],
			"广州": ["广州广百北京路", "广州友谊环市东", "广州天环广场", "广州广百中怡"],
			"宜昌": ["宜昌国贸"],
			"南昌": ["南昌铜锣湾T16", "南昌百盛"],
			"长沙": ["长沙平和堂", "长沙王府井", "长沙友谊袁家岭"],
			"武汉": ["武汉武商广场", "武汉新世界", "武汉群光"],
			"昆明": ["昆明百盛", "昆明恒隆", "昆明金格汇都", "昆明顺城王府井"],
			"贵阳": ["贵阳国贸", "贵阳星力", "贵阳亨特"],
			"佛山": ["佛山王府井"],
			"东莞": ["东莞汇一城"],
			"上海": ["上海港汇", "上海兴业太古汇", "上海百盛淮海", "上海大丸百货", "上海梅龙镇伊势丹", "上海国金", "上海东方商厦徐汇", "上海第一八佰伴", "上海久光", "上海东方商厦南东", "上海新世界", "上海前滩太古汇", "上海万象城"],
			"北京": ["北京新世界", "北京国贸", "北京西单大悦城", "北京新光天地", "北京燕莎亮马", "北京百盛", "北京翠微", "北京王府井", "北京当代", "北京王府井双安", "北京君太", "北京汉光", "北京燕莎金源", "北京合生汇"],
			"成都": ["成都万象城", "成都连卡佛", "成都仁和新城", "成都伊势丹", "成都王府井总府", "成都茂业光华", "成都群光", "成都王府井科华"],
			"重庆": ["重庆茂业", "重庆王府井", "重庆万象城", "重庆世纪新都"],
			"常州": ["常州泰富", "常州购物中心"],
			"福州": ["福州东百"],
			"杭州": ["杭州西湖银泰", "杭州大厦", "杭州银泰武林店", "杭州万象城", "杭州庆春银泰", "杭州IN77"],
			"厦门": ["厦门SM广场", "厦门万象城"],
			"南京": ["南京德基", "南京中央", "南京金鹰", "南京大洋", "南京新百", "南京景枫"],
			"徐州": ["徐州金鹰"],
			"合肥": ["合肥百货大楼", "合肥银泰"],
			"南通": ["南通文峰"],
			"淮安": ["淮安新亚"],
			"宁波": ["宁波银泰", "宁波坂急", "宁波万象城（22.1.5开业）"],
			"温州": ["温州开太", "温州万象城", "温州银泰"],
			"苏州": ["苏州泰华", "苏州美罗", "苏州中心"],
			"无锡": ["无锡商业大厦", "无锡八佰伴", "无锡恒隆"],
			"义乌": ["义乌银泰"],
			"金华": ["金华一百（12.20开业）"],
			"保定": ["保定先天下"],
			"石家庄": ["石家庄北国先天下", "石家庄万象城", "石家庄北国"],
			"包头": ["包头百货"],
			"天津": ["天津海信", "天津伊势丹", "天津友谊", "天津大悦城", "天津塘沽金元宝"],
			"太原": ["太原王府井", "太原华宇", "太原天美"],
			"郑州": ["郑州大卫城", "郑州丹尼斯人民店", "郑州丹尼斯花园店", "郑州正宏城"],
			"乌鲁木齐": ["乌鲁木齐汇嘉", "乌鲁木齐美美", "乌鲁木齐友好天百", "乌鲁木齐友好美美"],
			"兰州": ["兰州中心", "兰州国芳"],
			"呼和浩特": ["呼和浩特振华", "呼和浩特维多利", "呼和浩特维多利广场店"],
			"济南": ["济南万象城", "济南贵和", "济南银座"],
			"西安": ["西安开元", "西安王府井", "西安赛格", "西安SKP", "西安中大", "西安金鹰"],
			"洛阳": ["洛阳王府井百货"],
			"淄博": ["淄博银座"],
			"聊城": ["聊城振华"],
			"临沂": ["临沂银座"],
			"东营": ["东营银座"],
			"济宁": ["济宁贵和"],
			"唐山": ["唐山振华", "唐山百货"],
			"西宁": ["西宁王府井", "西宁大象城"],
			"烟台": ["烟台振华"],
			"青岛": ["青岛海信"],
			"银川": ["银川新华", "银川国芳"],
			"鞍山": ["鞍山百盛"],
			"吉林": ["吉林国贸"],
			"哈尔滨": ["哈尔滨群力", "哈尔滨远大", "哈尔滨松雷", "哈尔滨卓展"],
			"沈阳": ["沈阳万象城", "沈阳新玛特", "沈阳中兴", "沈阳卓展", "沈阳铁西万象汇"],
			"长春": ["长春卓展", "长春欧亚", "长春欧亚大卖场"],
			"大连": ["大连麦凯乐", "大连柏威年", "大连友谊"]
	},
		popDYshow:false,
		popGTshow:false,
		userinfo:"",
		clickable:true
	},
	onLoad(){
		var userinfo = wx.getStorageSync('memberinfo')
		if(userinfo.counter){
			this.setData({
				counter: userinfo.counter
			})
		}
		// wx.hideHomeButton()
	},
	bindMultiPickerChange: function(e) {
		var array=this.data.array;
		console.log('picker改变，携带值为', e.detail.value)
		this.setData({
			counter: array[2][e.detail.value[2]]
		})
	},
	bindMultiPickerColumnChange:function(e){
		var data = {
			array:this.data.array,
			cityarr :this.data.cityarr,
			counterarr:this.data.counterarr,
			tmparr:this.data.tmparr
		}
		
		switch (e.detail.column) {
			  case 0:
					data.array[1] = data.cityarr[data.array[0][e.detail.value]];
					data.array[2] = data.counterarr[data.cityarr[data.array[0][e.detail.value]][0]];
					data.tmparr[0] = e.detail.value; 
					this.setData({indexarr:[e.detail.value,0,0]})
				break;

				case 1:
					data.array[2] = data.counterarr[data.cityarr[data.array[0][this.data.tmparr[0]]][e.detail.value]];	
					this.setData({indexarr:[this.data.indexarr[0],e.detail.value,0]})
					break;

		}
		console.log(e.detail)
		this.setData(data)
		
	},
	startBtn:function(){

		if(this.data.counter == "请选择专柜"){
			wx.showToast({
				title: "您还没有选择专柜哦",
				icon:'none'
			})
			return false;
		}
		this.setData({
			popGTshow:true
		})
	},
	closeBtn:function(){
		this.setData({
			popGTshow:false
		})
		
	},
	
	submitBtn:function(){
		if(this.data.clickable == false){
			return false;
		}
		console.log(111)
		this.setData({clickable:false})
   	var that = this;
		setTimeout(function(){
			that.setData({clickable:true})
		},3000)

		var userinfo = wx.getStorageSync('memberinfo')

		var data ={counter:that.data.counter,openid:userinfo.openid}
		wx.request({
			url: app.globalData.apiurl+'access.php?a=addCoupon', 
			header: {
				"Content-Type": "application/x-www-form-urlencoded"
			},
			data: data,
			method:"POST",
			success (res) {
				if(res.data.status == 1){
					that.setData({
						popGTshow:false,
						popDYshow:true
					})
				}else{
					wx.showToast({
						title: res.data.info,
						icon:'none'
					})
				}
				
			}
		})

	},
	goPage:function(){
		wx.redirectTo({
			url: '/pages/cardinfo/cardinfo'
		})
	},
	
	
})
